package com.quanyan.riding.web;

import com.github.ltsopensource.core.json.JSON;
import com.quanyan.api.APIResponse;
import com.quanyan.common.utils.StringUtil;
import com.quanyan.riding.entity.vo.req.ReqRidingFootPrint;
import com.quanyan.riding.entity.vo.req.ReqRidingPathUser;
import com.quanyan.riding.entity.vo.resp.RespRidingPathUser;
import com.quanyan.riding.service.RidingPathService;
import com.quanyan.riding.util.RunRidingEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author xian-guo
 * @email 498152332@qq.com
 * @date 2016/8/29.
 */
@RestController
@RequestMapping(value = "api/riding")
public class RidingPathController {

    private static final Logger LOGGER = LoggerFactory.getLogger(RidingPathController.class);

    /**
     * 路书
     */
    @Autowired
    private RidingPathService ridingPathService;

    /**
     * 查找城市所有的路书路径
     * @param paramMap
     * @return
     */
    @RequestMapping(value = "ridingPathMessage",method = RequestMethod.POST)
    public APIResponse getRidingPathMessage(@RequestBody(required = true) Map<String,Object> paramMap){
        LOGGER.debug("--------------->>>>"+JSON.toJSONString(paramMap));
        Integer cityId= (Integer) paramMap.get("cityId");
        if (null == cityId){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingPathService.getRidingPathMessage(cityId);
    }

    /**
     * 进入路书页面查询路书上用户和足迹信息
     * @param reqRidingPathUser
     * @return
     */
    @RequestMapping(value = "ridingPathUserPrint",method = RequestMethod.POST)
    public APIResponse<RespRidingPathUser> getRidingPathUserPrint(@RequestBody(required = true) ReqRidingPathUser reqRidingPathUser){
        LOGGER.debug("--------------->>>>"+JSON.toJSONString(reqRidingPathUser));
        if (StringUtil.isBlankOrNull(reqRidingPathUser.getUserId()) || null ==reqRidingPathUser.getId() || StringUtil.isBlankOrNull(reqRidingPathUser.getCreateTime())){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingPathService.getRidingPathUserPrint(reqRidingPathUser);
    }

    /**
     * 上传用户足迹
     * @param reqRidingFootPrint
     * @return
     */
    @RequestMapping(value = "ridingFootPrintMsg",method = RequestMethod.POST)
    public APIResponse<RespRidingPathUser> insertRidingFootPrintMsg(@RequestBody(required = true) ReqRidingFootPrint reqRidingFootPrint){
        LOGGER.debug("--------------->>>>"+JSON.toJSONString(reqRidingFootPrint));
        if (StringUtil.isBlankOrNull(reqRidingFootPrint.getUserId()) || null ==reqRidingFootPrint.getPathId() ||StringUtil.isBlankOrNull(reqRidingFootPrint.getPhotoUrl())
                || StringUtil.isBlankOrNull(reqRidingFootPrint.getFootPrintDesc()) || StringUtil.isBlankOrNull(reqRidingFootPrint.getLongLat())){
            return APIResponse.returnFail(RunRidingEnum.PARAMETER_NOT_ALLOW_NULL);
        }
        return ridingPathService.insertRidingFootPrintMsg(reqRidingFootPrint);
    }


}
